home *** CD-ROM | disk | FTP | other *** search
- /* reverse.c - checks a phrase to see if it is a palindrome */
- #include "stdio.h"
-
- main()
- {
- char phrase[81] ;
- char rev_phrase[81] ;
-
- printf("Type a phrase : \n");/* prompt for phrase from keyboard */
- getstr(phrase,80) ; /* and get it */
-
- do_reverse(phrase,rev_phrase) ; /* construct reversed phrase */
- if( strcmp(phrase,rev_phrase) == 0 ) /* compare original */
- printf(" ** PALINDROME ** ");
- else printf(" REVERSE = %s",rev_phrase) ;
- }
-
- int do_reverse(s1,s2) /* reverse a string */
- char s1[] ; /* the string to be reversed */
- char s2[] ; /* place its reverse here */
- {
- int i , j ;
- /*copy characters starting at end of s1 */
- i = 0 ;
- j = strlen(s1) - 1 ; /* find index of last character in s1 */
- while( j >= 0 )
- { s2[i] = s1[j] ;
- i = i + 1 ;
- j = j - 1 ;
- }
- s2[i] = 0 ; /* mark end of string */
- }
-
-